package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.ProjectItemDO;
import com.smart.model.request.ProjectItemRequest;
import com.smart.model.request.ProjectWeeklyItemPageRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface ProjectItemMapper extends BaseMapper<ProjectItemDO> {
    ProjectItemDO selectDOById(Long id);
    List<ProjectItemDO> selectDOList(ProjectItemDO projectItem);
    int insertDO(ProjectItemDO projectItem);
    int batchInsertDO(List<ProjectItemDO> projectItemDOList);
    int updateDO(ProjectItemDO projectItem);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from project_item",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") ProjectItemRequest param);
    @Select({"<script>",
            "   select * from project_item",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<ProjectItemDO> pageQuery(@Param("param") ProjectItemRequest param, @Param("limit") int limit, @Param("offset") long offset);
    @Select("select * from project_item where task_id=#{taskId} order by sort_num asc")
    List<ProjectItemDO> listByTaskId(Long taskId);


    @Select({"<script>",
            "   select count(1) from project_item",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.weeklyTaskId!=null\">and task_id=#{param.weeklyTaskId}</if>",
            "   </where>",
            "</script>"})
    long pageItemCount(@Param("param") ProjectWeeklyItemPageRequest param);
    @Select({"<script>",
            "   select * from project_item",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.weeklyTaskId!=null\">and task_id=#{param.weeklyTaskId}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<ProjectItemDO> pageItemQuery(@Param("param") ProjectWeeklyItemPageRequest param, @Param("limit") int limit, @Param("offset") long offset);
}
